import request from '@/utils/request'
import type {
  LoginRequest,
  LoginResponse,
  RegisterRequest,
  RegisterResponse,
  RefreshTokenResponse,
  UpdateProfileRequest,
  User
} from '@/types/auth'
import type { ApiResponse } from '@/types/api'

export const authApi = {
  // Login
  login(data: LoginRequest): Promise<ApiResponse<LoginResponse>> {
    return request.post('/auth/login', data)
  },

  // Register
  register(data: RegisterRequest): Promise<ApiResponse<RegisterResponse>> {
    return request.post('/auth/register', data)
  },

  // Logout
  logout(): Promise<ApiResponse<void>> {
    return request.post('/auth/logout')
  },

  // Refresh token
  refreshToken(): Promise<ApiResponse<RefreshTokenResponse>> {
    return request.post('/auth/refresh')
  },

  // Get user profile
  getProfile(): Promise<ApiResponse<User>> {
    return request.get('/user/profile')
  },

  // Update user profile
  updateProfile(data: UpdateProfileRequest): Promise<ApiResponse<User>> {
    return request.put('/user/profile', data)
  }
}